//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.wsd.smartcarwasher.service;

import com.github.pagehelper.PageHelper;
import com.wsd.smartcarwasher.dao.RecordDao;
import com.wsd.smartcarwasher.domain.MessageRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class RecordService {
    private static final Logger logger = LoggerFactory.getLogger(RecordService.class);
    @Resource
    private RecordDao recordDao;

    public RecordService() {
    }

    void addRecord(MessageRecord messageRecord) {
        if (!"C".equalsIgnoreCase(messageRecord.getLevel())) {
            int changeRows = this.recordDao.addRecord(messageRecord);
            if (changeRows == 0) {
                logger.error("fail to add record", messageRecord);
            }

        }
    }

    public List<MessageRecord> queryMessageRecords(String machineId, String orderSn, String level, String eventCode, Date startTime, Date endTime, Integer status,Integer Page,Integer PageSize) {
        PageHelper.startPage(Page,PageSize);
        return this.recordDao.queryMessageRecords(machineId, orderSn, level, eventCode, startTime, endTime, status);
    }
    //查询手洗事件记录表
    public List<MessageRecord> querylOfflineMessageRecords(String machineId, String level, String eventCode, Date startTime, Date endTime, Integer status,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return this.recordDao.queryOfflineMessageRecords(machineId,  level, eventCode, startTime, endTime, status);
    }
    public boolean changeRecordStatus(MessageRecord messageRecord) {
        if (this.recordDao.changeRecordStatus(messageRecord) == 0) {
            logger.info(String.format("fail to change record with id = %s status to %s", messageRecord.getId(), messageRecord.getStatus()));
            return false;
        } else {
            return true;
        }
    }
}


/*
package com.wsd.smartcarwasher.service;

import com.wsd.smartcarwasher.constans.Global;
import com.wsd.smartcarwasher.dao.RecordDao;
import com.wsd.smartcarwasher.domain.MessageRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class RecordService {
    private static final Logger logger = LoggerFactory.getLogger(RecordService.class);

    @Resource
    private RecordDao recordDao;

    void addRecord(MessageRecord messageRecord) {
        if (Global.MACHINE_EVENT_LEVEL_C.equalsIgnoreCase(messageRecord.getLevel())) {
            return;
        }
        int changeRows = recordDao.addRecord(messageRecord);
        if (changeRows == 0) {
            logger.error("fail to add record", messageRecord);
        }
    }

    public List<MessageRecord> queryMessageRecords(String machineId, String orderSn, String level,
                                                   String eventCode, Date startTime, Date endTime) {
        return recordDao.queryMessageRecords(machineId, orderSn, level, eventCode, startTime, endTime);
    }
}
*/
